var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    allTotal: "",
    userId: "",
    sendUserId: "",
    orderId: "",
    receiptContacts: "",
    receiptTelephone: "",
    paymentTypeText: "", //paymentType: 1,// 支付方式 1 线下 2 微信 3 银行卡 4 余额
    allTotal: "",
    ifShowV: true,
    ifbuthiddenV: true,
    flag: 0,
    statusSelect: "", //判断是否选中
    checks: [],
    comment: "匿名评价用户",
    arrayChecks: "",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;
    var paymentType = options.paymentType;
    that.setData({
      userId: options.userId,
      sendUserId: options.sendUserId,
      orderId: options.orderId,
      receiptContacts: "*" + options.receiptContacts.substr(1),
      receiptTelephone: options.receiptTelephone.substr(0,3) + "****" + options.receiptTelephone.substr(7, 11),
      allTotal: options.allTotal
    });
    if (paymentType == 1) {
      that.setData({ paymentTypeText: "线下支付" });
    } else if (paymentType == 2) {
      that.setData({ paymentTypeText: "微信支付" });
    } else if (paymentType == 3) {
      that.setData({ paymentTypeText: "银行卡支付" });
    } else if (paymentType == 4) {
      that.setData({ paymentTypeText: "余额支付" });
    }

  },

  bindFormSubmit: function () {
    var that = this;
    that.setData({ ifShowV: false });
  },

  changeColor1: function () {
    var that = this;
    that.setData({
      ifbuthiddenV: false,
      flag: 1,
      checks: [{
        name: "货量少",
        value: '0',
        checked: false
      }, {
        name: "货质一般",
        value: '1',
        checked: false
      }, {
        name: "回收频率低",
        value: '2',
        checked: false
      }, {
        name: "不守信用",
        value: '3',
        checked: false
      }],
      comment: "一般用户"
    });
  },
  changeColor2: function () {
    var that = this;
    that.setData({
      ifbuthiddenV: false,
      flag: 2,
      checks: [{
        name: "货量少",
        value: '0',
        checked: false
      }, {
        name: "货质一般",
        value: '1',
        checked: false
      }, {
        name: "回收频率低",
        value: '2',
        checked: false
      }, {
        name: "不守信用",
        value: '3',
        checked: false
      }],
      comment: "一般用户"
    });
  },
  changeColor3: function () {
    var that = this;
    that.setData({
      flag: 3,
      ifbuthiddenV: false,
      checks: [{
        name: "货量较多",
        value: '0',
        checked: false
      }, {
        name: "货质优良",
        value: '1',
        checked: false
      }, {
        name: "回收有频率",
        value: '2',
        checked: false
      }, {
        name: "态度较好",
        value: '3',
        checked: false
      }],
      comment: "优质用户",
    });
  },
  changeColor4: function () {
    var that = this;
    that.setData({
      ifbuthiddenV: false,
      flag: 4,
      checks: [{
        name: "货量较多",
        value: '0',
        checked: false
      }, {
        name: "货质优良",
        value: '1',
        checked: false
      }, {
        name: "回收有频率",
        value: '2',
        checked: false
      }, {
        name: "态度较好",
        value: '3',
        checked: false
      }],
      comment: "优质用户",
    });
  },
  changeColor5: function () {
    var that = this;
    that.setData({
      ifbuthiddenV: false,
      flag: 5,
      checks: [{
        name: "货量大",
        value: '0',
        checked: false
      }, {
        name: "货质优",
        value: '1',
        checked: false
      }, {
        name: "回收频率高",
        value: '2',
        checked: false
      }, {
        name: "态度好",
        value: '3',
        checked: false
      }],
      comment: "VIP用户",
    });
  },

  clicks: function (e) {

    let index = e.currentTarget.dataset.index;
    let arrs = this.data.checks;
    let array = new Array;
    let text = e.currentTarget.dataset.text;
    if (arrs[index].checked == false) {
      arrs[index].checked = true;
      array.push(text);
    } else {
      arrs[index].checked = false;
    }
    this.setData({
      checks: arrs
    })

  },

  // 提交清空当前值
  bindSubmit: function () {
    var that = this;
    var checks = that.data.checks;
    var array = new Array;

    for (var i = 0; i < checks.length; i++) {
      if (checks[i].checked == true) {
        array.push(checks[i].name);
      }
    }
    that.setData({ arrayChecks: array })
   
    if (array.length <= 0) {
      wx.showToast({
        title: '评价类别必选',
        icon: 'none',
        duration: 1500,
      })
      return;
    }
    that.setData({ buthiddenV: true });
    wx.request({
      method: "POST",
      url: 'https://www.zaishengwang.com/wx/toSaveEvaluate.do',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        userId: that.data.userId,
        sendUserId: that.data.sendUserId,
        orderId: that.data.orderId,
        score: that.data.flag,
        label: that.data.arrayChecks
      },
      success: function (res) {
        var c = 2;
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 1500,

        })
        var intervalId = setInterval(function () {
          c = c - 1;
          if (c == 0) {
            clearInterval(intervalId);
            that.setData({ ifShowV: true });
            wx.reLaunch({
              url: 'home?finish=1',
            })
          }
        }, 1000)

      },
      fail: function (error) {
      }
    })

  },

  //评价隐藏
  cancelV: function () {
    var that = this;
    that.setData({ ifShowV: true });
    wx.reLaunch({
      url: 'home?finish=1',
    })

  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})